#!/usr/bin/env python

##################################
#                                #
#   NNTIME Proxy Grabber Beta    #
#                                #
##################################


########################################################################
# Basic NNTIME Proxy Parser Experimental                               #
#                                                                      #
# Now properly parses IP & Port,                                       #
# found anonymity type to be a bit useless feature for now.            #
#                                                                      #
# Features to be included:                                             #
# Support for multiple pages (Easy to implement, couldn't due to lack  #
#                             of time)                                 #
# Proxy Country (Optional)                                             #
# Proxy ISP/Owner (Optional)                                           #
# Proxy Last Upadate Time (Optional)                                   #
# Proxy Anonymity Level (Has been included for now,                    #
#                        but will be an  optional feature)             #
########################################################################

import urllib2, re

from time import sleep, ctime
from sys import exit 

def nntime_parser():
    
    variables = ()
    var_list = []
    final_var = {}
    temp_data = ()
    master_data = []
    symbol = u'\u25A3'
    
    print symbol*75
    print ''
    print '\t\t\tNNTIME PROXY PARSER BETA\n'
    print symbol*75
    print '\n\n'


    ua = 'Mozilla/5.0 (X11; U; Linux i686; en-US) Chrome/6.0.407.0'
    req = urllib2.Request('http://nntime.com/')
    req.add_header('User-Agent', ua)
    
    try:
        source = (urllib2.urlopen(req)).read()
    except(KeyboardInterrupt, BaseException):
         print '[-] Error Occured!'
         print '[*] Either System is Offline'
         print '[*] Or Force Quit was Attempted'
         sleep(2)
         exit(1)

    # pattern1 searches for values of variables, which are needed for finding proxy port
    pattern1 = re.compile('<script type="text/javascript">\s+(\S+);</script>')
   
    # pattern2 finds IP along with the port variables whose values we found in pattern1
    pattern2 = re.compile('</td><td>(\d+\.\d+\.\d+\.\d+)<script type="text/javascript">document\.write\(":"\+(\S+)\)\S+\s+<td>([\w|\s]+)</td>')

    variables = pattern1.findall(source)

    # values of the tuple 'variables' are assigned to a list for parsing
    var_list = variables

    # final_var is a dictionary storing required values, properly parsed
    for x in var_list:        
        x = x.split(';')
        for y in x:
            y = y.split('=')
            final_var[y[0]] = y[1]

    ip = pattern2.findall(source) 
    
    for i in ip:
        y = ''
        x = i[1]
        x = x.split('+')
        for j in x:
            y += final_var[j] 
        temp_data = (i[2], i[0], y)
        master_data.append(temp_data)

    master_data.sort()

    print 'Anonymity Level:\tProxy-Address:'
    print '=============== \t=============\n'

    for i in master_data:
        print '%s%s:%s' % (i[0].ljust(24, ' '), i[1], i[2])

    print '\n'
    print '*'*75
    print '[+] Total Proxies Found: %s' % (len(master_data))
    print '-'*75


if __name__ == '__main__':
    nntime_parser()





















